package arithmetic.leetCode.yi;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: yilin
 * Date: 2019-08-26
 * Time: 15:42
 */
public class SubberString {


    public static void main(String[] args) {
        System.out.println(countSubstrings2nd("ebcde"));

    }

    static int num = 0;

    private static int countSubstrings2nd(String s) {
        for (int i = 0; i < s.length(); i++) {
            countSub(s, i, i);//字符串的长度是奇数，中心点就是i本身
            countSub(s, i, i + 1);//字符串长度是偶数，中心点是i+1
        }
        return num;
    }

    private static void countSub(String s, int left, int right) {

        while (left >= 0 && right < s.length() && s.charAt(left) == s.charAt(right)) {
            left--;
            right++;
            num++;
        }
    }


}
